/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Ee Ting
 */
@Entity
public class BillOfMaterial implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long BOMId;
    
    @OneToMany(cascade = {CascadeType.PERSIST})
    private List<Component> compList = new ArrayList<Component>();
    
    private int unit;
    
    public void create(List<Component> tmpComp,int num)
    {
        this.setComp(tmpComp);
        this.setUnit(num);
    }
    
    public void addComp(Component comp)
    {
        compList.add(comp);
    }
    
    public List<Component> getComp() {
        return compList;
    }

    public void setComp(List<Component> comp) {
        this.compList = comp;
    }

    

    public int getUnit() {
        return unit;
    }

    public void setUnit(int unit) {
        this.unit = unit;
    }

    public Long getBOMId() {
        return BOMId;
    }

    public void setBOMId(Long BOMid) {
        this.BOMId = BOMid;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (BOMId != null ? BOMId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BillOfMaterial)) {
            return false;
        }
        BillOfMaterial other = (BillOfMaterial) object;
        if ((this.BOMId == null && other.BOMId != null) || (this.BOMId != null && !this.BOMId.equals(other.BOMId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.BillOfMaterial[ id=" + BOMId + " ]";
    }
    
}
